package lc.q151_200;

/**
 * 寻找旋转数组最小元素
 */
public class Q153 {

    public int findMin(int[] nums) {
        // 正常来讲就是nums[0]
        // 但是可能出现了旋转
        return findMin(nums, 0, nums.length);
    }

    private int findMin(int[] nums, int start, int end) {
        if (end - start <= 1) {
            return nums[start];
        }
        if (nums[start] < nums[end - 1]) {
            return nums[start];
        }
        int leftMin = findMin(nums, start, (start + end) / 2);
        int rightMin = findMin(nums, (start + end) / 2, end);
        return Math.min(leftMin, rightMin);
    }

    public static void main(String[] args) {
        int[] nums = {4,5,6,7,8,1,2,3};
        Q153 q153 = new Q153();
        int min = q153.findMin(nums);
        System.out.println(min);
    }

}
